<?php

// Define path to application directory
defined('APPLICATION_PATH')
        || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/application'));

// Define application environment
defined('APPLICATION_ENV')
        || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));


// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
            realpath(APPLICATION_PATH . '/../library'),
            get_include_path(),
        )));


set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path());
set_include_path(APPLICATION_PATH . '/modules/default/controllers' . PATH_SEPARATOR . get_include_path());

//Load bootstrap
define('ENVIRONMENT', 'env');
define('BASE_URL', 'http://' . $_SERVER['SERVER_NAME']);
define('DOMAIN', $_SERVER['SERVER_NAME']);
$domain = explode(".", DOMAIN);
define('DOCUMENT_DOMAIN', $domain[count($domain) - 2] . '.' . $domain[count($domain) - 1]);
define('APP_CONFIG', 'appConfig');
define('APP_ENV', isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'development');


define("TEMPLATE_URL", "templates");
define("UPLOAD_URL", "upload");

try {
    /** Zend_Application */
    require_once 'Zend/Application.php';

// Create application, bootstrap, and run
    $application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );

    /** start auto loader */
    $loader = Zend_Loader_Autoloader::getInstance();
    $loader->setFallbackAutoloader(true);

    $application->bootstrap()->run();
} catch (Zend_Exception $exception) {
    echo '<html><body><center>'
    . 'An exception occured while bootstrapping the application.';
    echo APP_ENV . '<br/>';
    if (APP_ENV != 'production') {
        echo '<br /><br />' . $exception->getMessage() . '<br />'
        . '<div align="left">Stack Trace:'
        . '<pre>' . $exception->getTraceAsString() . '</pre></div>';
    }
    echo '</center></body></html>';
    exit(1);
}
